package pers.liyan.shi.sytest;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Main {

    public static void main(String[] args) throws InterruptedException {

        int threadCount = 10;

        ExecutorService service = Executors.newFixedThreadPool(10);

        int appleCount = 100;

        Food food = new Food(appleCount * threadCount);

        for (int i = 0; i < threadCount; i++) {
            int index = i;
            service.execute(() -> {
                Animal animal = new Animal("Animal" + index);
                for (int j = 0; j < appleCount; j++) {
                    animal.eatApple(food);
                }
            });
        }

        service.shutdown();

        Thread.sleep(1000);
        System.out.println(food.getCount());

    }

    // static class Thread1 implements Runnable{
    //
    //     private Animal animal;
    //
    //     public Thread1(Animal animal) {
    //         this.animal = animal;
    //     }
    //
    //     @Override
    //     public void run() {
    //         try {
    //             this.animal.eatMeat();
    //         } catch (InterruptedException e) {
    //             e.printStackTrace();
    //         }
    //     }
    // }
    //
    // static class Thread2 implements Runnable{
    //
    //     private Animal animal;
    //
    //     public Thread2(Animal animal) {
    //         this.animal = animal;
    //     }
    //
    //     @Override
    //     public void run() {
    //         this.animal.eatApple();
    //         try {
    //             this.animal.eatMeat();
    //         } catch (InterruptedException e) {
    //             e.printStackTrace();
    //         }
    //     }
    // }

}
